package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.result.Result;
import com.example.entity.vo.CmsmvVo;
import com.example.entity.yifei.Cmsmv;
import com.example.mapper.CmsmvMapper;
import com.example.service.CmsmvService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LiangPandeng
 * @since 2024-02-22
 */
@Slf4j
@RestController
@RequestMapping("/api/cmsmv")
@Api(tags = "员工信息接口")
public class CmsmvController {

    @Resource
    private CmsmvService cmsmvService;
    @Resource
    private CmsmvMapper cmsmvMapper;

    @GetMapping("/mv002Select")
    @ApiOperation("根据姓名模糊查询员工信息")
    public Result mv002Select(@RequestBody(required = false) String mv002){
        List<CmsmvVo> cmsmvVoList = cmsmvService.selectLike(mv002);
        return Result.success(cmsmvVoList);
    }

    @GetMapping("/likeSelect")
    @ApiOperation("根据姓名模糊查询员工信息")
//    @ApiImplicitParam(name = "mv002",value = "员工姓名",dataType = "String",paramType = "query")
    public Result likeSelect(@RequestParam(value = "mv002") String mv002){
        List<CmsmvVo> cmsmvVoList = cmsmvService.selectLike(mv002);
        return Result.success(cmsmvVoList);
    }

    @GetMapping("/businessmanList")
    @ApiOperation("查询业务员信息列表")
    public Result<List<CmsmvVo>> businessmanList(){
        List<CmsmvVo> list = cmsmvMapper.selectVoByMK003("3");
        return Result.success(list);
    }

    @GetMapping("/salesmanList")
    @ApiOperation("查询销售人员信息列表")
    public Result<List<CmsmvVo>> salesmanList(){
        List<CmsmvVo> list = cmsmvMapper.selectVoByMK003("3");
        return Result.success(list);
    }

    @GetMapping("/purchaseStaffList")
    @ApiOperation("查询采购人员信息列表")
    public Result<List<CmsmvVo>> purchaseStaffList(){
        List<CmsmvVo> list = cmsmvMapper.selectVoByMK003("4");
        return Result.success(list);
    }

    @GetMapping("/getEmpByDept")
    @ApiOperation("根据部门获取员工列表")
    public Result<List<CmsmvVo>> getEmpByDept(@RequestParam String deptNo){
        ArrayList<CmsmvVo> cmsmvVos = new ArrayList<>();
        List<Cmsmv> list = cmsmvMapper.selectList(new QueryWrapper<Cmsmv>().in("MV004", deptNo));
        for (Cmsmv cmsmv : list) {
            CmsmvVo cmsmvVo = new CmsmvVo();
            cmsmvVo.setMv001(cmsmv.getMv001());
            cmsmvVo.setMv002(cmsmv.getMv002());
            cmsmvVos.add(cmsmvVo);
        }
        return Result.success(cmsmvVos);
    }

    @GetMapping("/all")
    @ApiOperation("根据条件获取部门员工信息")
    public Result getAll(String MV001, String MV002){
        return Result.ok(cmsmvService.getAll(MV001,MV002));
    }
}
